using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VLMFILMV
    {
        public DataRow Convert2LMFILMV(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryLMFILMV(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["LMVMANDANT"] = " ".PadRight(2 ); 
         dwReturn["LMVFILMNR"] = " ".PadRight(10 ); 
         dwReturn["LMVFSTA"] = " ".PadRight(1 ); 
         dwReturn["LMVSTGRD"] = " ".PadRight(3 ); 
         dwReturn["LMVBESCH"] = " ".PadRight(30 ); 
         dwReturn["LMVATEL"] = " ".PadRight(8 ); 
         dwReturn["LMVHERST"] = " ".PadRight(8 ); 
         dwReturn["LMVATDAT"] = " ".PadRight(0 ); 
         dwReturn["LMVHEDAT"] = " ".PadRight(0 ); 
         dwReturn["LMVANZFIG"] = " ".PadRight(0 ); 
         dwReturn["LMVEXCLU"] = " ".PadRight(8 ); 
         dwReturn["LMVLO"] = " ".PadRight(2 ); 
         dwReturn["LMVLB"] = " ".PadRight(2 ); 
         dwReturn["LMVLP"] = " ".PadRight(6 ); 
         dwReturn["LMVAUFBKZ"] = " ".PadRight(1 ); 
         dwReturn["LMVFILLER"] = " ".PadRight(83 ); 
         dwReturn["LMVAENDZL"] = " ".PadRight(0 ); 
         dwReturn["LMVAENDBEN"] = " ".PadRight(8 ); 
         dwReturn["LMVAENDDAT"] = " ".PadRight(0 ); 
         dwReturn["LMVNEUBEN"] = " ".PadRight(8 ); 
         dwReturn["LMVNEUDAT"] = " ".PadRight(0 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapLMFILMV(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveLMFILMV(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryLMFILMV(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapLMFILMV(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertLMFILMV(dwLocal, ITXDBVERSION);
            }
            UpdateLMFILMV(dwLocal);
        }
        public void InsertLMFILMV(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO LMFILMV(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryLMFILMV(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM LMFILMV WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM LMFILMV  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "LMFILMV";
            Return = Result;
            return Return;
        }
        public void DeleteLMFILMV(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM LMFILMV   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateLMFILMV(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE LMFILMV SET "
                    +"LMVMANDANT= :LMVMANDANT,"
                    +"LMVFILMNR= :LMVFILMNR,"
                    +"LMVFSTA= :LMVFSTA,"
                    +"LMVSTGRD= :LMVSTGRD,"
                    +"LMVBESCH= :LMVBESCH,"
                    +"LMVATEL= :LMVATEL,"
                    +"LMVHERST= :LMVHERST,"
                    +"LMVATDAT= :LMVATDAT,"
                    +"LMVHEDAT= :LMVHEDAT,"
                    +"LMVANZFIG= :LMVANZFIG,"
                    +"LMVEXCLU= :LMVEXCLU,"
                    +"LMVLO= :LMVLO,"
                    +"LMVLB= :LMVLB,"
                    +"LMVLP= :LMVLP,"
                    +"LMVAUFBKZ= :LMVAUFBKZ,"
                    +"LMVFILLER= :LMVFILLER,"
                    +"LMVAENDZL= :LMVAENDZL,"
                    +"LMVAENDBEN= :LMVAENDBEN,"
                    +"LMVAENDDAT= :LMVAENDDAT,"
                    +"LMVNEUBEN= :LMVNEUBEN,"
                    +"LMVNEUDAT= :LMVNEUDAT,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("LMVMANDANT", OracleType.NVarChar).Value = dwData["LMVMANDANT"].ToString(); 
          or1.Parameters.Add("LMVFILMNR", OracleType.NVarChar).Value = dwData["LMVFILMNR"].ToString(); 
          or1.Parameters.Add("LMVFSTA", OracleType.NVarChar).Value = dwData["LMVFSTA"].ToString(); 
          or1.Parameters.Add("LMVSTGRD", OracleType.NVarChar).Value = dwData["LMVSTGRD"].ToString(); 
          or1.Parameters.Add("LMVBESCH", OracleType.NVarChar).Value = dwData["LMVBESCH"].ToString(); 
          or1.Parameters.Add("LMVATEL", OracleType.NVarChar).Value = dwData["LMVATEL"].ToString(); 
          or1.Parameters.Add("LMVHERST", OracleType.NVarChar).Value = dwData["LMVHERST"].ToString(); 
          or1.Parameters.Add("LMVATDAT", OracleType.NVarChar).Value = dwData["LMVATDAT"].ToString(); 
          or1.Parameters.Add("LMVHEDAT", OracleType.NVarChar).Value = dwData["LMVHEDAT"].ToString(); 
          or1.Parameters.Add("LMVANZFIG", OracleType.NVarChar).Value = dwData["LMVANZFIG"].ToString(); 
          or1.Parameters.Add("LMVEXCLU", OracleType.NVarChar).Value = dwData["LMVEXCLU"].ToString(); 
          or1.Parameters.Add("LMVLO", OracleType.NVarChar).Value = dwData["LMVLO"].ToString(); 
          or1.Parameters.Add("LMVLB", OracleType.NVarChar).Value = dwData["LMVLB"].ToString(); 
          or1.Parameters.Add("LMVLP", OracleType.NVarChar).Value = dwData["LMVLP"].ToString(); 
          or1.Parameters.Add("LMVAUFBKZ", OracleType.NVarChar).Value = dwData["LMVAUFBKZ"].ToString(); 
          or1.Parameters.Add("LMVFILLER", OracleType.NVarChar).Value = dwData["LMVFILLER"].ToString(); 
          or1.Parameters.Add("LMVAENDZL", OracleType.NVarChar).Value = dwData["LMVAENDZL"].ToString(); 
          or1.Parameters.Add("LMVAENDBEN", OracleType.NVarChar).Value = dwData["LMVAENDBEN"].ToString(); 
          or1.Parameters.Add("LMVAENDDAT", OracleType.NVarChar).Value = dwData["LMVAENDDAT"].ToString(); 
          or1.Parameters.Add("LMVNEUBEN", OracleType.NVarChar).Value = dwData["LMVNEUBEN"].ToString(); 
          or1.Parameters.Add("LMVNEUDAT", OracleType.NVarChar).Value = dwData["LMVNEUDAT"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
